package ge.devfest.hackathon.gg.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class BitmapLoader {

	public Bitmap getBitmap(String path) {
		return BitmapFactory.decodeFile(path);
	}

	public Bitmap getScaledBitmap(String path, int width, int height) {
		BitmapFactory.Options opts = new BitmapFactory.Options();
		opts.inSampleSize = getSampleSize(path, width, height);
		return BitmapFactory.decodeFile(path, opts);
	}

	private int getSampleSize(String path, int dw, int dh) {
		BitmapFactory.Options opts = new BitmapFactory.Options();
		opts.inJustDecodeBounds = true;
		BitmapFactory.decodeFile(path, opts);
		int width = opts.outWidth;
		int height = opts.outHeight;
		return Math.min(width / dw, height / dh);
	}
}
